<!--- Sorting params --->
<cfparam name="orderBy" type="string" default="#client.institutionsOrderBy#">
<cfparam name="orderDir" type="string" default="#client.institutionsOrderDir#">
<!--- Filter params --->
<cfparam name="filterAccredited" type="string" default="#client.instituitonsAccredited#">
<cfparam name="filterDegreeGranting" type="string" default="#client.institutionsDegreeGranting#">
<cfparam name="filterApproved" type="string" default="#client.institutionsApproved#">
<cfparam name="filterDisqualified" type="string" default="#client.institutionsDisqualified#">
<!--- Status values: All, Approved, Unreviewed, Disqualified --->
<cfparam name="filterStatus" type="string" default="#client.institutionsStatus#">
<!--- Checkboxes --->
<cfparam name="institutionIDs" type="string" default="">

<!--- removed filterAccredited and filterDegreeGranting, so set their values to "All" in case a user had it filtered before the change --->
<cfset filterAccredited = "All">
<cfset filterDegreeGranting = "All">
<cfset filterApproved = "All">
<cfset filterDisqualified = "All">

<cfset institutions = application.institutionGateway.getAllAsQuery("*", orderBy, orderDir, filterAccredited, filterDegreeGranting, filterApproved, filterDisqualified, filterStatus)>

<cfoutput>

	<cfform name="institutionsForm" id="institutionsForm" action="#script_name#" method="post">
		<cfinput type="hidden" name="view" value="#view#">

		<div class="buttonBar">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<td>
						<!--- <cfif IsUserInRole("Super User")>
							<a href="#script_name#?view=createInstitution&rv=#view#&institutionID=0" class="formLink">New&nbsp;institution</a>
						</cfif>
						<cfif institutions.RecordCount gt 0>
							<a href="" onClick="emailSelected(); return false;" class="formLink">E-mail selected</a>
							<a href="/applications/admin/methods/export.cfm?view=#view#" target="_blank" class="formLink">Export</a>
						</cfif> --->
					</td>
					<td align="right">
						<strong>Count:</strong> #institutions.RecordCount#
					</td>
				</tr>
			</table>
		</div>

		<!--- filter --->

		<script type="text/javascript" language="javascript">
		<!--
			toggleVisibility = function(objId) {
				var obj = document.getElementById(objId);
				if (obj.style.visibility == "visible") {
					obj.style.visibility = "hidden";
					obj.style.display = "none";
				} else {
					obj.style.visibility = "visible";
					obj.style.display = "block";
				}
			}

			updateFilterLink = function() {
				if (document.getElementById("filterSelections").style.visibility == "visible") {
					document.getElementById("filterLink").innerHTML = '#minusImage#&nbsp;Hide Filter';
				} else {
					document.getElementById("filterLink").innerHTML = '#plusImage#&nbsp;Show Filter';
				}
			}

			updateIDsSelect = function(selectObj) {
				if (selectObj.selectedIndex == 0) {
					selectObj.selectedIndex = 0;
				}
			}
		// -->
		</script>

		<table class="filter" width="100%">
			<tr>
				<td class="filterHeader"><a id="filterLink" href="" onclick="toggleVisibility('filterSelections'); toggleVisibility('filterButtons'); updateFilterLink(); return false;" style="width: 100px; display: inline-block;">#plusImage#&nbsp;Show Filter</a><cfif filterAccredited neq "All" or filterDegreeGranting neq "All" or filterApproved neq "All" or filterStatus neq "All">List is filtered</cfif></td>
			</tr>
			<tr id="filterSelections" style="visibility: hidden; display: none;">
				<td>

					<table>
						<tr>
							<!--- <td>
								<fieldset>
									<legend>Accredited</legend>
									<input type="radio" id="accredited1" name="filterAccredited" value="All"<cfif filterAccredited eq "All"> checked="true"</cfif>><label for="accredited1">&nbsp;All</label><br>
									<input type="radio" id="accredited2" name="filterAccredited" value="Yes"<cfif filterAccredited eq "Yes"> checked="true"</cfif>><label for="accredited2">&nbsp;Yes</label><br>
									<input type="radio" id="accredited3" name="filterAccredited" value="No"<cfif filterAccredited eq "No"> checked="true"</cfif>><label for="accredited3">&nbsp;No</label>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>Degree Granting</legend>
									<input type="radio" id="degreeGranting1" name="filterDegreeGranting" value="All"<cfif filterDegreeGranting eq "All"> checked="true"</cfif>><label for="degreeGranting1">&nbsp;All</label><br>
									<input type="radio" id="degreeGranting2" name="filterDegreeGranting" value="Yes"<cfif filterDegreeGranting eq "Yes"> checked="true"</cfif>><label for="degreeGranting2">&nbsp;Yes</label><br>
									<input type="radio" id="degreeGranting3" name="filterDegreeGranting" value="No"<cfif filterDegreeGranting eq "No"> checked="true"</cfif>><label for="degreeGranting3">&nbsp;No</label>
								</fieldset>
							</td> --->
							<!--- <td>
								<fieldset>
									<legend>Approved</legend>
									<input type="radio" id="approved1" name="filterApproved" value="All"<cfif filterApproved eq "All"> checked="true"</cfif>><label for="approved1">&nbsp;All</label><br>
									<input type="radio" id="approved2" name="filterApproved" value="Yes"<cfif filterApproved eq "Yes"> checked="true"</cfif>><label for="approved2">&nbsp;Approved</label><br>
									<input type="radio" id="approved3" name="filterApproved" value="No"<cfif filterApproved eq "No"> checked="true"</cfif>><label for="approved3">&nbsp;Not approved</label>
								</fieldset>
							</td> --->
							<td>
								<fieldset>
									<legend>Status</legend>
									<input type="radio" id="status1" name="filterStatus" value="All"<cfif filterStatus eq "All"> checked="true"</cfif>><label for="status1">&nbsp;All</label><br>
									<input type="radio" id="status2" name="filterStatus" value="Approved"<cfif filterStatus eq "Approved"> checked="true"</cfif>><label for="status2">&nbsp;Approved</label><br>
									<input type="radio" id="status3" name="filterStatus" value="Unreviewed"<cfif filterStatus eq "Unreviewed"> checked="true"</cfif>><label for="status3">&nbsp;Unreviewed</label><br>
									<input type="radio" id="status4" name="filterStatus" value="Disqualified"<cfif filterStatus eq "Disqualified"> checked="true"</cfif>><label for="status4">&nbsp;Disqualified</label>
								</fieldset>
							</td>
							<td width="100%"></td>
						</tr>
					</table>

				</td>
			</tr>
			<tr id="filterButtons" style="visibility: hidden; display: none;">
				<td>
					<div style="margin-bottom: 4px;">
						<cfinput type="submit" name="applyFilterButton" id="applyFilterButton" value="Apply Filter" class="formButton2">
						<cfif filterAccredited neq "All" or filterDegreeGranting neq "All" or filterApproved neq "All" or filterStatus neq "All">
							<a href="#script_name#?view=#view#&filterAccredited=All&filterDegreeGranting=All&filterApproved=All&filterStatus=All" class="formLink2">Clear filter</a>
						</cfif>
					</div>
				</td>
			</tr>
		</table>

		<cfif institutions.RecordCount gt 0>

			<!--- checkbox functions --->
			<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
				<script type="text/javascript" language="javascript">
				<!--
					toggleSelectAll = function(f) {
						var c = f.selectAllCheckbox;
						for (var i=0; i<f.institutionIDs.length; i++) {
							if (c.checked) {
								f.institutionIDs[i].checked = true;
							} else {
								f.institutionIDs[i].checked = false;
							}
						}
					}

					updateSelectAll = function(chk) {
						if (!chk) {
							document.getElementById("selectAllCheckbox").checked = false;
						}
					}

					emailSelected = function() {
						var f = document.getElementById("usersForm");
						var institutionIDs = new Array();
						for (var i=0; i<f.institutionIDs.length; i++) {
							if (f.institutionIDs[i].checked) {
								institutionIDs[institutionIDs.length] = f.institutionIDs[i].value;
							}
						}
						if (institutionIDs.length == 0) {
							alert("Select at least one institution");
						} else {
							eSF = document.getElementById("emailSelectedForm");
							eSF.institutionIDs.value = institutionIDs;
							eSF.submit();
						}
					}
				// -->
				</script>
			</cfif>

			<table class="list" width="100%">
				<tr>
					<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
						<th><input name="selectAllCheckbox" id="selectAllCheckbox" type="checkbox" onclick="toggleSelectAll(this.form);"></th>
					</cfif>
					<th><a href="#script_name#?view=#view#&orderBy=Institution_ID<cfif orderBy eq 'Institution_ID' and orderDir eq 'asc'>&orderDir=desc</cfif>">ID<cfif orderBy eq "Institution_ID">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Institution<cfif orderBy eq 'Institution' and orderDir eq 'asc'>&orderDir=desc</cfif>">Institution<cfif orderBy eq "Institution">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<!--- <th><a href="#script_name#?view=#view#&orderBy=Location<cfif orderBy eq 'Location' and orderDir eq 'asc'>&orderDir=desc</cfif>">Location<cfif orderBy eq "Location">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th> --->
					<th><a href="#script_name#?view=#view#&orderBy=Term_Type<cfif orderBy eq 'Term_Type' and orderDir eq 'asc'>&orderDir=desc</cfif>">Term Type<cfif orderBy eq "Term_Type">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Accredited<cfif orderBy eq 'Accredited' and orderDir eq 'asc'>&orderDir=desc</cfif>">Accredited<cfif orderBy eq "Accredited">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Degree_Granting<cfif orderBy eq 'Degree_Granting' and orderDir eq 'asc'>&orderDir=desc</cfif>">Degree Granting<cfif orderBy eq "Degree_Granting">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Segment<cfif orderBy eq 'Segment' and orderDir eq 'asc'>&orderDir=desc</cfif>">Segment<cfif orderBy eq "Segment">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=scholarshipCount<cfif orderBy eq 'scholarshipCount' and orderDir eq 'asc'>&orderDir=desc</cfif>">Scholarships<cfif orderBy eq "scholarshipCount">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=paymentCount<cfif orderBy eq 'paymentCount' and orderDir eq 'asc'>&orderDir=desc</cfif>">Payments<cfif orderBy eq "paymentCount">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<!--- <th><a href="#script_name#?view=#view#&orderBy=Approved<cfif orderBy eq 'Approved' and orderDir eq 'asc'>&orderDir=desc</cfif>">Status<cfif orderBy eq "Approved">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th> --->
					<th><a href="#script_name#?view=#view#&orderBy=Approved,Disqualified<cfif orderBy eq 'Approved,Disqualified' and orderDir eq 'asc'>&orderDir=desc</cfif>">Status<cfif orderBy eq "Approved,Disqualified">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
				</tr>
				<cfloop query="institutions">
					<tr<cfif currentRow mod 2 eq 0> class="evenRow"<cfelse> class="oddRow"</cfif>>
						<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
							<td><input type="checkbox" name="institutionIDs" value="#Institution_ID#" onclick="updateSelectAll(this.checked);"<cfif ListFind(institutionIDs, Institution_ID)> checked</cfif>></td>
						</cfif>
						<td><a href="#script_name#?view=editInstitution&rv=#view#&institutionID=#Institution_ID#">#Institution_ID#</a></td>
						<td>#Institution#</td>
						<!--- <td>#Institution_City#, #Institution_State#</td> --->
						<td>#Term_Type#</td>
						<td>
							<cfif IsBoolean(Accredited)>
								#YesNoFormat(Accredited)#
							</cfif>
						</td>
						<td>
							<cfif IsBoolean(Degree_Granting)>
								#YesNoFormat(Degree_Granting)#
							</cfif>
						</td>
						<td>
						<cfif Segment eq "Com Col">
							Community College
						<cfelseif Segment eq "2 Yr Priv">
							2 Year Private
						<cfelseif Segment eq "4 Yr Priv">
							4 Year Private
						<cfelseif Segment eq "CSU">
							CSU
						<cfelseif Segment eq "Prop">
							Proprietary/For-Profit
						<cfelseif Segment eq "UC">
							UC
						<cfelseif Segment eq "2 Yr Pub non-CA">
							2 Year Public, non-CA
						<cfelseif Segment eq "4 Yr Priv non-CA">
							4 Year Private, non-CA
						<cfelseif Segment eq "4 Yr Pub non-CA">
							4 Year Public, non-CA
						</cfif>
						</td>
						<!--- <td><a href="#script_name#?view=scholarships&filterSearchCriteria=#Institution#">#scholarshipCount#</a></td> --->
						<td>#scholarshipCount#</td>
						<td>#paymentCount#</td>
						<!--- <td>
							<cfif Approved>
								Approved
							<cfelseif Disqualified>
								<font color="red">Disqualified</font>
							<cfelse>
								<font color="orange">Unreviewed</font>
							</cfif>
						</td> --->
						<td>
							<cfif Approved eq 1 and Disqualified eq 0>
								Approved
							<cfelseif Approved eq 0 and Disqualified eq 1>
								<font color="red">Disqualified</font>
							<cfelseif Approved eq 0 and Disqualified eq 0>
								<font color="orange">Unreviewed</font>
							<cfelse>
								Error determining status
							</cfif>
						</td>
					</tr>
				</cfloop>
			</table>

		</cfif>

	</cfform>

	<cfif institutions.RecordCount eq 0>

		<div class="alert alert-info notFound">No institutions with the selected filter criteria</div>

		<!--- show filter --->
		<cfif authUser.getRole() neq "Site Contact">
			<script type="text/javascript" language="javascript">
			<!--
				toggleVisibility('filterSelections');
				toggleVisibility('filterButtons');
				updateFilterLink();
			// -->
			</script>
		</cfif>

	</cfif>

</cfoutput>